#!/bin/bash

# default size, as in makefile, 1024^2

# $1: dag/omp/ori
function test_all_parameters() 
{
    get_exec  $1 
    for iter in  100 
        do
            for BS in  32 64 128 256 512
                do
                    for nthreads in 1 2 4 8 
                    do
                    for((i=0;i<$num_run;i++))
                    do
                    echo $1 $iter $BS $nthreads " ">>$logfile
                    echo -n $1 $iter $BS $nthreads " ">>$outfile
                    ./gauss_$1 $BS $iter $nthreads >tmp
		            grep "total time: " tmp | awk '{print $3}' >> $outfile
		            cat tmp >>$logfile
                done
            done
        done
    done
}

#$1, dag/omp/ori
#$2, BS
#$3, iter
function test_one_parameter() 
{
    for nthreads in 1 2 4 8
    do
        for((i=0;i<$num_run;i++))
        do
            echo $2 $3 $nthreads " ">>$logfile
            echo -n $2 $3 $nthreads " ">>$outfile
            ./gauss_$1 $2 $3 $nthreads >tmp
		    grep "total time: " tmp | awk '{print $3}' >> $outfile
		    cat tmp >>$logfile
        done
    done
}
#$1, dag/omp/ori
function get_exec()
{
    make clean
	make $1 
}

#$1, dag/omp/ori
#$2, BS
#$3, iter
function do_one_test()
{
    get_exec  $1 
    test_one_parameter $1 $2 $3
}


testcase=('gauss')
flagname=("")

lenth=${#testcase[*]}
num_run=3
for((i=0;i<$lenth;i++))
do
	dir="data"
	mkdir $dir
    curdate=$(date +%Y_%m_%d_%H_%M_%S)
    outfile="$dir/${testcase[$i]}_$curdate.txt"
    logfile="$dir/${testcase[$i]}_$curdate.log"
    # do_one_test dag 64 100
    test_all_parameters dag
done
